package com.cysoft.log.demo.event.listener;

import com.alibaba.fastjson.JSON;
import com.cysoft.starter.log.core.model.LogEvent;
import com.cysoft.starter.log.core.model.LogInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author 玖零
 * @version V0.0.1
 * @project demo-cysoft-starter-log
 * @package com.cysoft.log.demo.event.listener
 * @date 2025-02-27 15:54
 * @desc
 */
@Slf4j
@Component
public class LogInfoEventListener{

    @EventListener
    public void onApplicationEvent(LogEvent logEvent) {
        log.info("监听到日志Event：{}", JSON.toJSONString(logEvent.getSource()));
        LogInfo logInfo = JSON.parseObject(JSON.toJSONString(logEvent.getSource()), LogInfo.class);
        log.info("转换后logInfo：{}", logInfo);
    }
}
